package drds.server;

import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import drds.server.common.$;
import drds.server.config.model.DRDS;

public final class Startup {
	private static final Logger LOGGER = LoggerFactory.getLogger(Startup.class);

	public static void main(String[] args) {
		LOGGER.info(Server.PRETTIFY_LINE);
		LOGGER.info("沁园春·雪");
		LOGGER.info("北国风光，千里冰封，万里雪飘。");
		LOGGER.info("望长城内外，惟馀莽莽；大河上下，顿失滔滔。");
		LOGGER.info("山舞银蛇，原驰蜡象，欲与天公试比高。");
		LOGGER.info("须晴日，看红妆素裹，分外妖娆。");
		LOGGER.info("江山如此多娇，引无数英雄竞折腰。");
		LOGGER.info("惜秦皇汉武，略输文采；唐宗宋祖，稍逊风骚。");
		LOGGER.info("一代天骄，成吉思汗，只识弯弓射大雕。");
		LOGGER.info("俱往矣，数风流人物，还看今朝。");
		LOGGER.info(Server.PRETTIFY_LINE);
		try {
			String DRDS_HOME = DRDS.getDRDSHomePath();
			if (DRDS_HOME == null) {
				System.out.println(DRDS.DRDS_HOME + "  is not set.");
				System.exit(-1);
			}
			LOGGER.info(Server.PRETTIFY_LINE);

			ExecutorService executorService = Executors.newCachedThreadPool();
			Runnable command = new Runnable() {

				@Override
				public void run() {
					try {
						TimeUnit.MINUTES.sleep(1);
					} catch (InterruptedException e) {
						// e.printStackTrace();
					}

				}
			};
			executorService.execute(command);
			// 系统退出指令executorService.shutdownNow();
			while (true) {
				Scanner scanner = new Scanner(System.in);
				String line = scanner.nextLine();
				if ("quit".equals(line)) {
					executorService.shutdownNow();
					break;
				} else if ("start".equals(line)) {
					System.out.println("DRDS 服务端启动中");
				}

			}
		} catch (Exception e) {
			LOGGER.error($.Exception.getStackTrace("系统异常", e));
			System.exit(-1);
		}
	}

}
